/**
 * @Method input
 * @Description TODO
 * @Date 2021/1/20 9:52
 * @Created by HePing
 */
export default {
  model: {
    prop: 'model'
  },
  props: {
    model: {},
    config: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  render(h) {
    const vm = this
    const {
      slots,
      widget: { style, nativeOn, props, attrs, className }
    } = vm.config
    const children = []
    const makeSlots = (slots = {}, slotName) => {
      const { value, type } = slots[slotName] || {}
      if (!value) return
      if (type === 'COMPONENT') {
        children.push(
          <template slot={slotName}>
            {
              h(
                value,
                {
                  props: {
                    config: vm.config
                  },
                  on: vm.$listeners
                }
              )
            }
          </template>
        )
      } else if (type === 'HTML') {
        children.push(<ve-html slot={slotName} value={value} />)
      }
    }
    makeSlots(slots, 'prepend')
    makeSlots(slots, 'append')
    if (!children.length) children.push(vm.$slots.default)
    return h(
      'el-input',
      {
        attrs,
        style: style,
        props: {
          ...props,
          value: vm.model
        },
        on: vm.$listeners,
        nativeOn,
        class: className
      },
      children
    )
  }
}
